﻿Module ControlsModule
    Public Sub PlayerControl(ByRef action As String, type As String)
        Select Case action

            '' Back Button actions to take depending on the variable for
            Case "back"
                FormMain.wmp.Ctlcontrols.previous()

                '' Stop Button actions to take depending on the variable 
            Case "stop"
                FormMain.wmp.Ctlcontrols.stop()
                FormMain.pct01Back.Enabled = False
                FormMain.pct02Stop.Enabled = False
                FormMain.pct03Pause.Enabled = False
                FormMain.pct04Play.Enabled = True
                FormMain.pct05Next.Enabled = False
                If My.Settings.WindowerDisplay = "single" Then
                    DisplayTrack("FFXI Media Player [Stopped]")
                ElseIf My.Settings.WindowerDisplay = "multi" Then
                    DisplayTrack("FFXI Media Player" + vbNewLine + "Player Stopped")
                End If
                '' Stop Button actions to take depending on the variable 
            Case "pause"
                FormMain.wmp.Ctlcontrols.pause()
                FormMain.pct01Back.Enabled = False
                FormMain.pct02Stop.Enabled = True
                FormMain.pct03Pause.Enabled = False
                FormMain.pct04Play.Enabled = True
                FormMain.pct05Next.Enabled = False
                If My.Settings.WindowerDisplay = "single" Then
                    DisplayString = ""
                    DisplayString = "FFXI Media Player [Paused] - "
                    If My.Settings.ShowArtist = True Then DisplayString = DisplayString + "Artist: " + Track.Artist + " "
                    If My.Settings.ShowTitle = True Then DisplayString = DisplayString + "| Title: " + Track.Title + " "
                    If My.Settings.ShowDuration = True Then DisplayString = DisplayString + "| Duration: " + Track.Duration
                    DisplayTrack(DisplayString)
                ElseIf My.Settings.WindowerDisplay = "multi" Then
                    DisplayString = ""
                    DisplayString = "FFXI Media Player" + vbNewLine + "Player Paused"
                    If My.Settings.ShowArtist = True Then DisplayString = DisplayString + vbNewLine + "Artist: " + Track.Artist
                    If My.Settings.ShowTitle = True Then DisplayString = DisplayString + vbNewLine + "Title: " + Track.Title
                    If My.Settings.ShowDuration = True Then DisplayString = DisplayString + vbNewLine + "Duration: " + Track.Duration
                    DisplayTrack(DisplayString)
                End If
                '' Stop Button actions to take depending on the variable 
            Case "play"
                FormMain.wmp.Ctlcontrols.play()

                FormMain.pct01Back.Enabled = True
                FormMain.pct02Stop.Enabled = True
                FormMain.pct03Pause.Enabled = True
                FormMain.pct04Play.Enabled = True
                FormMain.pct05Next.Enabled = True

                '' Stop Button actions to take depending on the variable 
            Case "next"
                FormMain.wmp.Ctlcontrols.next()

                '' Stop Button actions to take depending on the variable 
            Case "file"
                If type = "playlist" Then
                    Dim playlist As WMPLib.IWMPPlaylist
                    Dim newmedia As WMPLib.IWMPMedia

                    playlist = FormMain.wmp.newPlaylist("NowPlaying", "") 'resets the playlist for everytime you open files
                    FormMain.wmp.currentPlaylist = playlist
                    If FormMain.OpenPlaylist.ShowDialog = DialogResult.OK Then 'opens dialog box to allow user to select m3u or wpl
                        newmedia = FormMain.wmp.newMedia(FormMain.OpenPlaylist.FileName) 'sets the newmedia
                        FormMain.wmp.currentPlaylist.insertItem(0, newmedia) 'inserts the new media into playlist
                        FormMain.pct04Play.Enabled = True
                        If My.Settings.WindowerDisplay = "single" Then
                            DisplayTrack("FFXI Media Player loaded playlist")
                        ElseIf My.Settings.WindowerDisplay = "multi" Then
                            DisplayTrack("FFXI Media Player" + vbNewLine + "Loaded playlist")
                        End If
                        displayupdate = True
                        FormMain.pct04Play.Enabled = True
                    Else
                        displayupdate = False
                    End If

                End If

            Case "volume"



                '' Stop Button actions to take depending on the variable 
            Case "power"

        End Select
    End Sub

    Public Sub CreateDisplayString()
        If WinInit.Detect = True Then
            If displayupdate = True Then
                If My.Settings.WindowerDisplay = "single" Then
                    DisplayString = ""
                    DisplayString = "FFXI Media Player [Playing] - "
                    If My.Settings.ShowArtist = True Then DisplayString = DisplayString + "Artist: " + Track.Artist + " "
                    If My.Settings.ShowTitle = True Then DisplayString = DisplayString + "| Title: " + Track.Title + " "
                    If My.Settings.ShowDuration = True Then DisplayString = DisplayString + "| Duration: " + Track.Possition + "/" + Track.Duration
                ElseIf My.Settings.WindowerDisplay = "multi" Then
                    DisplayString = ""
                    DisplayString = "FFXI Media Player" + vbNewLine + "Now playing"
                    If My.Settings.ShowArtist = True Then DisplayString = DisplayString + vbNewLine + "Artist: " + Track.Artist
                    If My.Settings.ShowTitle = True Then DisplayString = DisplayString + vbNewLine + "Title: " + Track.Title
                    If My.Settings.ShowDuration = True Then DisplayString = DisplayString + vbNewLine + "Duration: " + Track.Possition + "/" + Track.Duration
                End If
            End If
        End If
    End Sub

    Public Sub UpdateDisplay()
        CreateDisplayString()
        DisplayTrack(DisplayString)
    End Sub
   
End Module
